﻿

namespace FileStrider
{
    using System;
    using System.Windows.Controls;
    using System.IO;

    /// <summary>
    /// Interaction logic for ListItemDrive.xaml
    /// </summary>
    public partial class ListItemDrive : UserControl
    {
        private DriveInfo Drive;
        public bool? IsSelected
        {
            get { return CheckBoxSelectToScan.IsChecked; }
        }
        public string DriveName
        {
            get { return Drive.Name; }
        }

        public ListItemDrive(string driveName)
        {
            InitializeComponent();

            var driveInfo = new DriveInfo(driveName);
            Drive = driveInfo;
            LabelDiskName.Content = driveInfo.Name;
            if (driveInfo.IsReady)
            {
                LabelUsed.Content = "Used " +
                                    ((driveInfo.TotalSize - driveInfo.TotalFreeSpace)/1024/1024/1024).ToString("N1") + "Gb";
            }
            else
            {
                // disable check box, so drive cannot be scanned
                CheckBoxSelectToScan.IsEnabled = false;
                LabelUsed.Content = "";
            }

            ImageIcon.Source = Helper.GetDriveIcon(driveName);
        }
        
        public void ResetProgress()
        {
            Dispatcher.Invoke((Action)delegate { ProgressBarScanned.Value = 0; });
        }

        public void Progress(long size)
        {
            if (size == 0) return;
            long usedSpace = (Drive.TotalSize - Drive.TotalFreeSpace)/1024/1024;
            Dispatcher.Invoke((Action)delegate { ProgressBarScanned.Value += (100 * (double)size) / (double)usedSpace; });
        }
    }
}
